#include "GY_RepeatGroup.h"
#include <QDebug>

GY_RepeatGroup::GY_RepeatGroup(const QString &guid, QGraphicsItem *parent)
    : GY_ContainerTransform(guid,this, parent)
{
    initializationPropertyInfo();
    this->setCenterPointF(m_PropertyInfoMap["Position"].propertyValue.toPointF());
}

void GY_RepeatGroup::setName()
{
//    m_copyItemMap.insert(pItem,vec);
//    m_ChildrensMap.insert(pItem->getGuid(),pItem);
//    m_OrderChildrens.append(pItem);
    for(const auto& key : m_copyItemMap.keys()) {
//        int i = m_copyItemMap.value(key).size()-1;
        for(const auto& l : m_copyItemMap.value(key)) {
//            l->setObjName(QString(key->getObjName()+"_+_=_%1").arg(i--));
//            qDebug()<<l->getObjName()<<"name";

            QString name = l->getObjName();
            int ind = name.indexOf("_+_=_");
            if(ind != -1) {
                name.insert(ind,QString("___0"));
            }
//            qDebug()<<name<<"namewai";
            l->setObjName(name);

            if(l->inherits("GY_ContainerTransform")) {
                  ((GY_ContainerTransform*)l)->setTapeCircularChildObjName(QString("___0"));
            }
        }
        key->setObjName(key->getObjName()+"___0");
        ((GY_ContainerTransform*)key)->setChildObjName(QString("___0"));
    }
}

bool GY_RepeatGroup::addItem(GY_Object *pItem)
{
    int repeatCount = m_PropertyInfoMap["RepeatCount"].propertyValue.toInt();
    //设置新添图形复制个数
    pItem->setRepeatNum(repeatCount);
    //存放复制品容器
    QVector<GY_Object*> vec;
    //原item名称，复制品名称为(原名称_+_=_%1)
    QString pItemName = pItem->getObjName();

    //原版item属性map
    QMap<QString,GY_PropertyInfo> test = pItem->getPropertyMap();

    if(pItem->inherits("GY_BasicsGraphicsObject") && repeatCount != 0)
    {
        for(int i=0;i<repeatCount;i++) {
            GY_Object *copyItem = pItem->copyItem();
            //复制品对象名称设置，方便查找
            copyItem->setObjName(QString(pItemName+"_+_=_%1").arg(i));
            vec.push_front(copyItem);
            this->addToGroup((GY_BasicsGraphicsObject*)copyItem);

            //复制品有父级后再次更新属性
            QMap<QString,GY_PropertyInfo>::Iterator iter = test.begin();
            while (iter != test.end()) {
                if(((iter.value().updateType)&PointOfRelative) == PointOfRelative) {
                    copyItem->updateProperty(iter.key(), submittingPropertyValues(iter.value().updateType,iter.value().propertyValue,(GY_BasicsGraphicsObject*)pItem));
                }else if(((iter.value().updateType)&NotUpdate) == NotUpdate){
                    ++iter;
                    continue;
                }else {
                    copyItem->updateProperty(iter.key(), iter.value().propertyValue);
                }
                ++iter;
            }
            //复制品对象名称设置，方便查找
            copyItem->setObjName(QString(pItemName+"_+_=_%1").arg(i));
        }
    }
    else if(pItem->inherits("GY_ContainerTransform") && repeatCount != 0)
    {
        ((GY_ContainerTransform*)pItem)->setChildRepeatNum(repeatCount);
        for(int i=0;i<repeatCount;i++) {
            GY_Object *copyItem = pItem->copyItem();
            //复制品对象名称设置，方便查找
            copyItem->setObjName(QString(pItemName+"_+_=_%1").arg(i));
//            ((GY_ContainerTransform*)copyItem)->setChildObjName(QString("_+_=_%1").arg(i));
            vec.push_front(copyItem);
            this->addToGroup((GY_ContainerTransform*)copyItem);

            //复制品有父级后再次更新属性
            QMap<QString,GY_PropertyInfo>::Iterator iter = test.begin();
            while (iter != test.end()) {
                if(((iter.value().updateType)&PointOfRelative) == PointOfRelative) {
                    copyItem->updateProperty(iter.key(), submittingPropertyValues(iter.value().updateType,iter.value().propertyValue,(GY_BasicsGraphicsObject*)pItem));
                }else if(((iter.value().updateType)&NotUpdate) == NotUpdate){
                    ++iter;
                    continue;
                }else {
                    copyItem->updateProperty(iter.key(), iter.value().propertyValue);
                }
                ++iter;
            }
            //复制品对象名称设置，方便查找
            copyItem->setObjName(QString(pItemName+"_+_=_%1").arg(i));
            ((GY_ContainerTransform*)copyItem)->setChildObjName(QString("_+_=_%1").arg(i));
        }
    }
    else if(pItem->inherits("GY_BasicsDataObjects"))
    {
//        vec.push_front(pItem);
    }
    else
    {
//        return false;
    }
    //插入原版和复制品
    m_copyItemMap.insert(pItem,vec);
    m_ChildrensMap.insert(pItem->getGuid(),pItem);
    m_OrderChildrens.append(pItem);

    //!原版属性和复制版属性关联
    connect(pItem,&GY_Object::updatePropertyEvent,this,&GY_RepeatGroup::updateCopyItemProperty);
    pItem->setConnect();

    return true;
}

bool GY_RepeatGroup::removItem(const QString &guid)
{
    if(!m_ChildrensMap.contains(guid))
    {
        return false;
    }
    m_ChildrensMap.remove(guid);
    return true;
}

bool GY_RepeatGroup::removItem(const GY_Object *pItem)
{
    //设置移出图形复制个数为0
    ((GY_Object*)pItem)->setRepeatNum(0);

    for(int i=0;i<m_copyItemMap[(GY_Object*)pItem].size()-1;i++) {
        //释放复制品
        m_copyItemMap[(GY_Object*)pItem][i]->deleteLater();
        //制空
        GY_Object *copyItem = m_copyItemMap[(GY_Object*)pItem][i];
        copyItem = nullptr;
    }
    if(pItem->inherits("GY_BasicsGraphicsObject"))
    {
        this->removeFromGroup((GY_BasicsGraphicsObject*)pItem);
    }
    else if(pItem->inherits("GY_ContainerTransform"))
    {
        this->removeFromGroup((GY_ContainerTransform*)pItem);
    }
    //在存放复制品map中删除item
    m_copyItemMap.remove((GY_Object*)pItem);
    if(m_OrderChildrens.contains((GY_Object *)pItem)) {
        m_OrderChildrens.removeOne((GY_Object *)pItem);
    }
    return  removItem(pItem->getGuid());
}

GY_Object *GY_RepeatGroup::getPurObject(const QString &purposeObjName, GY_Object *obj, QMap<QString, GY_Object *> childrensMap)
{
    QMap<GY_Object*,QVector<GY_Object*>>::Iterator iter = m_copyItemMap.begin();
    while (iter != m_copyItemMap.end()) {
        int iterValueSize = iter.value().size();
        for(int i=0;i<iterValueSize;i++) {
            QString objName = iter.value().at(i)->getObjName();
            if(objName == purposeObjName) {
                return iter.value().at(i);
            }
            //如果子类中有容器，再从容器中查找
            if(iter.value().at(i)->getUserData(GY_ENUM::ObjectType) == 1) {
                obj = iter.value().at(i)->getPurObject(purposeObjName, obj, ((GY_ContainerTransform*)iter.value().at(i))->getChildrensMap());
                if(obj != nullptr) {
                    return obj;
                }
            }
        }
        ++iter;
    }

    QMap<QString,GY_Object*>::Iterator iterName = childrensMap.begin();
    while (iterName != childrensMap.end()) {
        QString objName = iterName.value()->getObjName();
        if(objName == purposeObjName) {
            return iterName.value();
        }
        //如果子类中有容器，再从容器中查找
        if(iterName.value()->getUserData(GY_ENUM::ObjectType) == 1) {
            obj = iterName.value()->getPurObject(purposeObjName, obj, ((GY_ContainerTransform*)iterName.value())->getChildrensMap());
            if(obj != nullptr) {
                return obj;
            }
        }
        ++iterName;
    }
    return obj;
}

bool GY_RepeatGroup::checkVarName(const QStringList &list, QMap<QString, GY_Object *> childrensMap)
{
    if(list.at(0) == "") {
        return false;
    }

    QMap<GY_Object*,QVector<GY_Object*>>::Iterator iter = m_copyItemMap.begin();
    while (iter != m_copyItemMap.end()) {
        int iterValueSize = iter.value().size();
        for(int i=0;i<iterValueSize;i++) {
            QVariant objName;
            objName = iter.value().at(i)->getObjName();
            //查找名称是否存在
            if(objName.toString() == list.at(0)) {
                //查找属性是否存在
                QMap<QString,GY_PropertyInfo> property = iter.value().at(i)->getPropertyMap();
                if(list.size() == 2) {
                    if(property.contains(list.at(1))) {
                        return true;
                    }
                }
                if(list.size() == 3) {
                    if(property.contains(list.at(1)+"."+list.at(2))) {
                        return true;
                    }
                    if(property.contains(list.at(1))) {
                        if((list.at(2) == "X") || (list.at(2) == "Y")) {
                            return true;
                        }
                    }
                }
            }
            //如果子类中有容器，再从容器中查找
            if(iter.value().at(i)->getUserData(GY_ENUM::ObjectType) == 1) {
                bool child = iter.value().at(i)->checkVarName(list, ((GY_ContainerTransform*)iter.value().at(i))->getChildrensMap());
                if(child) {
                    return true;
                }
            }
        }
        ++iter;
    }

    QMap<QString,GY_Object*>::Iterator iterName = childrensMap.begin();
    while (iterName != childrensMap.end()) {
        QVariant objName;
        objName = iterName.value()->getObjName();
        //查找名称是否存在
        if(objName.toString() == list.at(0)) {
            //查找属性是否存在
            QMap<QString,GY_PropertyInfo> property = iterName.value()->getPropertyMap();
            if(list.size() == 2) {
                if(property.contains(list.at(1))) {
                    return true;
                }
            }
            if(list.size() == 3) {
                if(property.contains(list.at(1)+"."+list.at(2))) {
                    return true;
                }
                if(property.contains(list.at(1))) {
                    if((list.at(2) == "X") || (list.at(2) == "Y")) {
                        return true;
                    }
                }
            }
        }
        //如果子类中有容器，再从容器中查找
        if(iterName.value()->getUserData(GY_ENUM::ObjectType) == 1) {
            bool child = iterName.value()->checkVarName(list, ((GY_ContainerTransform*)iterName.value())->getChildrensMap());
            if(child) {
                return true;
            }
        }
        ++iterName;
    }
    return false;
}

PropertyType GY_RepeatGroup::getPurposeType(const QStringList &list, QMap<QString, GY_Object *> childrensMap)
{
    QMap<GY_Object*,QVector<GY_Object*>>::Iterator iter = m_copyItemMap.begin();
    while (iter != m_copyItemMap.end()) {
        int iterValueSize = iter.value().size();
        for(int i=0;i<iterValueSize;i++) {
            QVariant objName;
            objName = iter.value().at(i)->getObjName();
            //查找名称是否存在
            if(objName.toString() == list.at(0)) {
                //查找属性是否存在
                QMap<QString,GY_PropertyInfo> property = iter.value().at(i)->getPropertyMap();
                if(list.size() == 2) {
                    if(property.contains(list.at(1))) {
                        return property[list.at(1)].propertyType;
                    }
                }
                if(list.size() == 3) {
                    if(property.contains(list.at(1)+"."+list.at(2))) {
                        return property[list.at(1)+"."+list.at(2)].propertyType;
                    }
                    if(property.contains(list.at(1))) {
                        if((list.at(2) == "X") || (list.at(2) == "Y")) {
                            return property[list.at(1)].propertyType;
                        }
                    }
                }
            }
            //如果子类中有容器，再从容器中查找
            if(iter.value().at(i)->getUserData(GY_ENUM::ObjectType) == 1) {
                PropertyType tmp = iter.value().at(i)->getPurposeType(list, ((GY_ContainerTransform*)iter.value().at(i))->getChildrensMap());
                if(tmp != NullPropertyType) {
                    return tmp;
                }
            }
        }
        ++iter;
    }

    QMap<QString,GY_Object*>::Iterator iterType = childrensMap.begin();
    while (iterType != childrensMap.end()) {
        QVariant objName;
        objName = iterType.value()->getObjName();
        //查找名称是否存在
        if(objName.toString() == list.at(0)) {
            //查找属性是否存在
            QMap<QString,GY_PropertyInfo> property = iterType.value()->getPropertyMap();
            if(list.size() == 2) {
                if(property.contains(list.at(1))) {
                    return property[list.at(1)].propertyType;
                }
            }
            if(list.size() == 3) {
                if(property.contains(list.at(1)+"."+list.at(2))) {
                    return property[list.at(1)+"."+list.at(2)].propertyType;
                }
                if(property.contains(list.at(1))) {
                    if((list.at(2) == "X") || (list.at(2) == "Y")) {
                        return property[list.at(1)].propertyType;
                    }
                }
            }
        }
        //如果子类中有容器，再从容器中查找
        if(iterType.value()->getUserData(GY_ENUM::ObjectType) == 1) {
            PropertyType tmp = iterType.value()->getPurposeType(list, ((GY_ContainerTransform*)iterType.value())->getChildrensMap());
            if(tmp != NullPropertyType) {
                return tmp;
            }
        }
        ++iterType;
    }
    return NullPropertyType;
}

void GY_RepeatGroup::updateCopyItemProperty(const GY_Object *pObject, const QString &propertyName, const QVariant &propertyValue, const PropertyType &type)
{
//    qDebug()<<pObject<<propertyName<<propertyValue<<"------------------------------";
    if(propertyName == "ObjectName") {
        return;
    }
    if((pObject->isBind.contains(propertyName))&&(pObject->isBind[propertyName])) {
        return;
    }
    if(type == PointPropertyType) {
        QString propertyNameX = propertyName + ".X";
        QString propertyNameY = propertyName + ".Y";
        //X和Y，都绑定
        if((pObject->isBind.contains(propertyNameX))&&(pObject->isBind[propertyNameX])&&(pObject->isBind.contains(propertyNameY))&&(pObject->isBind[propertyNameY])) {
            return;
        }
        //X绑定，只修改Y值
        if((pObject->isBind.contains(propertyNameX))&&(pObject->isBind[propertyNameX])) {
            //qvector数组
            int m_copyItemMapSize = m_copyItemMap[(GY_Object*)pObject].size();
            for(int i=0;i<m_copyItemMapSize;i++) {
                m_copyItemMap[(GY_Object*)pObject].at(i)->updateProperty(propertyNameY,propertyValue.toPointF().y());
            }
            return;
        }
        //Y绑定，只修改X值
        if((pObject->isBind.contains(propertyNameY))&&(pObject->isBind[propertyNameY])) {
            //qvector数组
            int m_copyItemMapSize = m_copyItemMap[(GY_Object*)pObject].size();
            for(int i=0;i<m_copyItemMapSize;i++) {
                m_copyItemMap[(GY_Object*)pObject].at(i)->updateProperty(propertyNameX,propertyValue.toPointF().x());
            }
            return;
        }
    }

    //qvector数组
    int m_copyItemMapSize = m_copyItemMap[(GY_Object*)pObject].size();
    for(int i=0;i<m_copyItemMapSize;i++) {
        m_copyItemMap[(GY_Object*)pObject].at(i)->updateProperty(propertyName,propertyValue);
    }
}

void GY_RepeatGroup::initializationPropertyInfo()
{
    GY_PropertyInfo ObjectName(this);
    ObjectName.propertyName = "ObjectName";
    ObjectName.propertyValue = QString();
    ObjectName.updateType = Update|OrdinaryAttributes;
    ObjectName.propertyType = QStringPropertyType;
    ObjectName.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_RepeatGroup::updateObjectName;
    m_PropertyInfoMap.insert("ObjectName",ObjectName);
    m_PropertyInfoMap[ObjectName.propertyName].setConnect();

    //位置
    GY_PropertyInfo positonPropertyInfo(this);
    positonPropertyInfo.propertyName="Position";
    positonPropertyInfo.propertyValue=QPointF(0,0);
    positonPropertyInfo.updateType = Update|MoveUpdate|PointOfRelative;
    positonPropertyInfo.propertyType = PointPropertyType;
    positonPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_RepeatGroup::updatePosition;
    m_PropertyInfoMap.insert(positonPropertyInfo.propertyName,positonPropertyInfo);
    m_PropertyInfoMap[positonPropertyInfo.propertyName].setConnect();
    
    GY_PropertyInfo RepeatCount(this);
    RepeatCount.propertyName = "RepeatCount";
    RepeatCount.propertyValue = 0;
    RepeatCount.updateType = Update|OrdinaryAttributes;
    RepeatCount.propertyType = IntPropertyType;
    RepeatCount.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_RepeatGroup::updateRepeatCount;
    m_PropertyInfoMap.insert(RepeatCount.propertyName,RepeatCount);
    m_PropertyInfoMap[RepeatCount.propertyName].setConnect();
    
    GY_PropertyInfo LoopIndex(this);
    LoopIndex.propertyName = "LoopIndex";
    LoopIndex.propertyValue = 0;
//    LoopIndex.updateType = Update|OrdinaryAttributes;
    //不对外说明数值
    LoopIndex.updateType = NotUpdate;
    LoopIndex.propertyType = IntPropertyType;
    LoopIndex.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_RepeatGroup::updateLoopIndex;
    m_PropertyInfoMap.insert(LoopIndex.propertyName,LoopIndex);
    m_PropertyInfoMap[LoopIndex.propertyName].setConnect();
    
    GY_PropertyInfo LastConsumerIndex(this);
    LastConsumerIndex.propertyName = "LastConsumerIndex";
    LastConsumerIndex.propertyValue = 0;
    LastConsumerIndex.updateType = Update|OrdinaryAttributes;
    LastConsumerIndex.propertyType = IntPropertyType;
    LastConsumerIndex.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_RepeatGroup::updateLastConsumerIndex;
    m_PropertyInfoMap.insert(LastConsumerIndex.propertyName,LastConsumerIndex);
    m_PropertyInfoMap[LastConsumerIndex.propertyName].setConnect();
    
    GY_PropertyInfo FireLoopEvent(this);
    FireLoopEvent.propertyName = "FireLoopEvent";
    FireLoopEvent.propertyValue = false;
    FireLoopEvent.updateType = Update|OrdinaryAttributes;
    FireLoopEvent.propertyType = BoolPropertyType;
    FireLoopEvent.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_RepeatGroup::updateFireLoopEvent;
    m_PropertyInfoMap.insert(FireLoopEvent.propertyName,FireLoopEvent);
    m_PropertyInfoMap[FireLoopEvent.propertyName].setConnect();
}

bool GY_RepeatGroup::updatePosition(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    //setpos设置为父级坐标
    QPointF point = value.toPointF();
    if(this->parentItem()) {
        point = this->mapToParent(this->mapFromScene(value.toPointF()));
    }
    this->setPos(point);
    m_PropertyInfoMap[name].propertyValue=this->mapFromScene(value.toPointF());
    return true;
}

bool GY_RepeatGroup::updateRepeatCount(const QString &name, const QVariant &value)
{
    if(!value.canConvert<int>())
    {
        return false;
    }
    //之前复制数目
    int tmpValue = m_PropertyInfoMap[name].propertyValue.toInt();
    if(tmpValue == value.toInt()) {
        return true;
    }
    //新复制数目
    m_PropertyInfoMap[name].propertyValue = value;
    int valueToInt = value.toInt();
    if(valueToInt > m_MaxCount) {
        addLoopIndex(valueToInt);
    }
    //复制数目变小
    if(tmpValue > valueToInt) {
        QMap<QString,GY_Object*>::Iterator iter = m_ChildrensMap.begin();
        while (iter != m_ChildrensMap.end()) {
            //设置图形复制个数
            iter.value()->setRepeatNum(valueToInt);
            if(iter.value()->inherits("GY_ContainerTransform")) {
                ((GY_ContainerTransform*)iter.value())->setChildRepeatNum(valueToInt);
            }
            for(int i=valueToInt;i<tmpValue;i++) {
                //释放复制品vec中变少个数
                m_copyItemMap[iter.value()].first()->deleteLater();
                //制空
                m_copyItemMap[iter.value()].first() = nullptr;
                //在m_copyItemMap删除该复制品
                m_copyItemMap[iter.value()].removeFirst();
            }
            iter.value()->setConnect();
            ++iter;
        }
    }
    //复制数目变大
    else if(tmpValue < valueToInt) {
        QMap<QString,GY_Object*>::Iterator iter = m_ChildrensMap.begin();
        while (iter != m_ChildrensMap.end()) {
            //设置图形复制个数
            iter.value()->setRepeatNum(valueToInt);
            //原item名称，其余复制品名称为(原名称_+_=_%1)
            QString pItemName = iter.value()->getObjName();

            //原版item属性map
            QMap<QString,GY_PropertyInfo> test = iter.value()->getPropertyMap();
            //图元
            if(iter.value()->inherits("GY_BasicsGraphicsObject")) {
                for(int i=tmpValue;i<valueToInt;i++) {
                    //新增复制品vec中变多个数
                    GY_Object *copyItem = iter.value()->copyItem();
                    //复制品对象名称设置，方便查找
                    copyItem->setObjName(QString(pItemName+"_+_=_%1").arg(i));
                    m_copyItemMap[iter.value()].push_front(copyItem);
                    this->addToGroup((GY_BasicsGraphicsObject*)copyItem);

                    //复制品有父级后再次更新属性
                    QMap<QString,GY_PropertyInfo>::Iterator iterp = test.begin();
                    while (iterp != test.end()) {
                        if(((iterp.value().updateType)&PointOfRelative) == PointOfRelative) {
                            copyItem->updateProperty(iterp.key(), submittingPropertyValues(iterp.value().updateType,iterp.value().propertyValue,(GY_BasicsGraphicsObject*)iter.value()));
                        }else if(((iterp.value().updateType)&NotUpdate) == NotUpdate){
                            ++iterp;
                            continue;
                        }else {
                            copyItem->updateProperty(iterp.key(), iterp.value().propertyValue);
                        }
                        ++iterp;
                    }
                    //复制品对象名称设置，方便查找
                    copyItem->setObjName(QString(pItemName+"_+_=_%1").arg(i));
                }
            }
            //组件
            else if(iter.value()->inherits("GY_ContainerTransform")) {
//                qDebug()<<((GY_ContainerTransform *)iter.value())->getChildrensMap().keys().size()<<
//                          ((GY_ContainerTransform *)iter.value())->metaObject()->className()<<"sizeRE-------------------"<<pItemName;
                for(int i=tmpValue;i<valueToInt;i++) {
                    ((GY_ContainerTransform*)iter.value())->setChildRepeatNum(valueToInt);
                    //新增复制品vec中变多个数
                    GY_Object *copyItem = iter.value()->copyItem();
                    //复制品对象名称设置，方便查找
                    copyItem->setObjName(QString(pItemName+"_+_=_%1").arg(i));
//                    ((GY_ContainerTransform*)copyItem)->setChildObjName(QString("_+_=_%1").arg(i));
                    m_copyItemMap[iter.value()].push_front(copyItem);
                    this->addToGroup((GY_ContainerTransform*)copyItem);

                    //复制品有父级后再次更新属性
                    QMap<QString,GY_PropertyInfo>::Iterator iterp = test.begin();
                    while (iterp != test.end()) {
                        if(((iterp.value().updateType)&PointOfRelative) == PointOfRelative) {
                            copyItem->updateProperty(iterp.key(), submittingPropertyValues(iterp.value().updateType,iterp.value().propertyValue,(GY_BasicsGraphicsObject*)iter.value()));
                        }else if(((iterp.value().updateType)&NotUpdate) == NotUpdate){
                            ++iterp;
                            continue;
                        }else {
                            copyItem->updateProperty(iterp.key(), iterp.value().propertyValue);
                        }
                        ++iterp;
                    }
                    //复制品对象名称设置，方便查找
                    copyItem->setObjName(QString(pItemName+"_+_=_%1").arg(i));
                    ((GY_ContainerTransform*)copyItem)->setChildObjName(QString("_+_=_%1").arg(i));
                }
            }
            iter.value()->setConnect();
            ++iter;
        }
    }
    return true;
}

bool GY_RepeatGroup::updateLoopIndex(const QString &name, const QVariant &value)
{
//    if(!value.canConvert<int>())
//    {
//        return false;
//    }
//    m_PropertyInfoMap[name].propertyValue = value;
//    return true;
    Q_UNUSED(name);
    Q_UNUSED(value);
//    qDebug() << name << value;
    return false;
}

bool GY_RepeatGroup::updateLoopIndex1(const QString &name, const QVariant &value)
{
    if(!value.canConvert<int>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue = value;
    return false;
}

bool GY_RepeatGroup::updateLastConsumerIndex(const QString &name, const QVariant &value)
{
    if(!value.canConvert<int>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue = value;
    return true;
}

bool GY_RepeatGroup::updateFireLoopEvent(const QString &name, const QVariant &value)
{
    if(!value.canConvert<bool>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue = value;
    return true;
}

void GY_RepeatGroup::addLoopIndex(const int &count)
{
    for(int i=m_MaxCount;i<count;i++) {
        GY_PropertyInfo LoopIndex(this);
        LoopIndex.propertyName = QString("LoopIndex_%1").arg(i);
        LoopIndex.propertyValue = i;
        LoopIndex.updateType = Update|OrdinaryAttributes;
        LoopIndex.propertyType = IntPropertyType;
        LoopIndex.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_RepeatGroup::updateLoopIndex1;
        m_PropertyInfoMap.insert(LoopIndex.propertyName,LoopIndex);
        m_PropertyInfoMap[LoopIndex.propertyName].setConnect();
    }
    m_MaxCount = count;
}

